package day01_IO_JDBC.demo_JDBC_emp_pro.View;

import HanShuFangFa.SanGuoHero_pro;
import day01_IO_JDBC.demo_JDBC_emp.entity.Emp;
import day01_IO_JDBC.demo_JDBC_emp_pro.Controller.EmpController;
import day01_IO_JDBC.demo_JDBC_emp_pro.Entity.Emp2;
import org.junit.Test;

import java.util.List;
import java.util.Scanner;

public class EmpView {
    private static int emp_no=0;

//    @Test
//    public void test(){
//        new EmpView().login();
//    }

    public static void main(String[] args) {
                new EmpView().login();
    }

    private void adminMenu(){
        Scanner scanner= new Scanner(System.in);
        System.out.println("管理员，你好，欢迎使用员工管理系统");
        System.out.println("输入数字执行以下操作：");
        System.out.println("1、查询所有员工信息");
        System.out.println("2、根据员工id查询员工信息");
        System.out.println("3、添加员工信息");
        System.out.println("4、根据员工id删除员工信息");
        System.out.println("5、根据员工id修改员工信息");
        System.out.println("6、退出系统");

        int num= scanner.nextInt();
        while (true){
            switch (num){
                case 1 :
                    queryAll_emp2();
                    break;
                case 2 :
                    queryByEmpno();
                    break;
                case 3 : add_emp2();
                    break;
                case 4 :
                    delete_emp2();
                    break;
                case 5 :
                    admin_update_emp2();
                    break;
                case 6 :
                    System.exit(0);
            }
            break;
        }
    }

    public void empMenu(){
        Scanner scanner= new Scanner(System.in);
        System.out.println("员工，你好，欢迎使用员工管理系统");
        System.out.println("输入数字执行以下操作：");
        System.out.println("1、查询个人信息");
        System.out.println("2、修改个人信息：");
        System.out.println("3、退出系统");

        int num= scanner.nextInt();
        while (true){
            switch (num){
                case 1 :
                    queryByEmpno();
                    break;
                case 2 :
                    update_emp2();
                    break;
                case 3 :
                    System.exit(0);
            }
            break;
        }

    }

    public void login(){
        Scanner scanner= new Scanner(System.in);
        System.out.println("登录页面");
        System.out.println("请输入员工id：");
        int emp_no= scanner.nextInt();
        System.out.println("请输入账号：");
        String name= scanner.next();
        System.out.println("请输入密码：");
        String pwd= scanner.next();
        System.out.println("请输入权限：");
        int permission= scanner.nextInt();

        EmpController empController= new EmpController();
        int num= empController.login_emp2(emp_no, name, pwd, permission);
        if (num == 1){
            if (permission == 1){
                adminMenu();
            }
            else {
                EmpView.emp_no=emp_no;
                empMenu();
            }
        }
    }



    public void queryAll_emp2(){
        EmpController empController= new EmpController();
        List<Emp2> emp2List= empController.queryAll_emp2();
        if (emp2List != null){
            System.out.println("查询到的全部员工信息如下"+emp2List);
        }
        else {
            System.out.println("没有查询到任何员工信息");
        }
    }

    public void queryByEmpno(){
        EmpController empController= new EmpController();
        Scanner scanner= new Scanner(System.in);
        System.out.println("请输入你需要查询的员工id号：");
        int num= scanner.nextInt();
        List<Emp2> emp2List= empController.queryByEmpno(num);
        if (emp2List != null){
            System.out.println("根据员工id查询到的员工信息如下："+emp2List);
        }else {
            System.out.println("没有查询到指定员工信息");
        }
    }

    public void add_emp2(){
        EmpController empController= new EmpController();
        Scanner scanner= new Scanner(System.in);
        System.out.println("请输入员工姓名：");
        String name= scanner.next();
        System.out.println("请输入员工薪资");
        double salary= scanner.nextDouble();
        System.out.println("请输入权限（1：admin； 0：emp）");
        int permission= scanner.nextInt();

        Emp2 emp=new Emp2(0,name,"123",salary,permission);

        int num = empController.add_emp2(emp);
        if (num == 1){
            System.out.println("员工信息添加成功");
        }else {
            System.out.println("员工信息添加失败，请重新尝试");
        }
    }

    public void delete_emp2(){
        EmpController empController= new EmpController();
        Scanner scanner= new Scanner(System.in);
        System.out.println("请输入需要删除的员工id：");
        int num= scanner.nextInt();
        boolean bl= empController.delete_emp2(num);
        if (bl){
            System.out.println("编号为"+" "+num+" "+"的员工已执行删除操作");
        }else {
            System.out.println("删除操作执行失败，请重新尝试");
        }
    }

    public void admin_update_emp2(){
        EmpController empController= new EmpController();
        Scanner scanner= new Scanner(System.in);
        System.out.println("请输入需要修改的员工id：");
        int emp_no= scanner.nextInt();
        System.out.println("请输入员工的账号");
        String name= scanner.next();
        System.out.println("请输入员工的密码");
        String pwd= scanner.next();
        System.out.println("请输入工资");
        double salary= scanner.nextDouble();
        System.out.println("请输入权限(1  /  0)");
        int permission= scanner.nextInt();

        Emp2 emp= new Emp2(emp_no, name, pwd, salary,permission);

        boolean bl= empController.admin_update_emp2(emp);
        if (bl){
            System.out.println("个人信息管理员修改操作成功");
        }else {
            System.out.println("管理员修改操作失败");
        }
    }

    public void update_emp2(){

        EmpController empController= new EmpController();

        Scanner scanner= new Scanner(System.in);
        System.out.println("请输入你的账号：");
        String name= scanner.next();
        System.out.println("请输入你的密码：");
        String pwd= scanner.next();

        boolean bl= empController.update_emp2(emp_no, name, pwd);
        if (bl){
            System.out.println("个人信息员工修改操作成功");
        }else {
            System.out.println("员工修改操作失败");
        }
    }

}
